package cn.zjutleo.village_server.service;

import cn.zjutleo.village_server.constants.RedisConstants;
import cn.zjutleo.village_server.mapper.StarAndColletMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: 张坤
 * @DateTime: 2021/12/7 16:25
 * @Description: 该类用于 TODO
 */
@Service
public class StarAndColletService {
    @Resource
    private StarAndColletMapper starAndColletMapper;
    @Resource
    private RedisService redisService;

    /**
     * 点赞功能
     */
    public int addCollet(int userID,int policyID){
        redisService.setHyperLogLog(RedisConstants.POLICY_COLLECTION_CODE_PREFIX+policyID,userID);
        return starAndColletMapper.addCollet(userID,policyID);
    }
    /**
     * 收藏功能
     */
    public int addStar(int userID,int policyID){
        redisService.setHyperLogLog(RedisConstants.POLICY_STAR_CODE_PREFIX+policyID,userID);
        return starAndColletMapper.addStar(userID,policyID);
    }
    /**
     * 取消收藏功能
     */
    public int cancelCollet(int userID,int policyID){
        return starAndColletMapper.cancelCollet(userID,policyID);
    }
    /**
     * 取消点赞功能
     */
    public int cancelStar(int userID,int policyID){
        return starAndColletMapper.cancelStar(userID,policyID);
    }

    /**
     * 查询点赞功能
     */
    public long selectCollet(int policyID){
        return redisService.getHyperLogLog(RedisConstants.POLICY_COLLECTION_CODE_PREFIX+policyID);
    }
    /**
     * 查询收藏功能
     */
    public long selectStar(int policyID){
        return redisService.getHyperLogLog(RedisConstants.POLICY_STAR_CODE_PREFIX+policyID);
    }
}
